# 斐波那契数列
def fibonacci_generator():
    a, b = 0, 1
    while True:
        yield a
        a, b = b, a + b

# 使用生成器
fib_gen = fibonacci_generator()
for _ in range(10):
    print(next(fib_gen))






# class MyRange:
#     def __init__(self, start, end):
#         self.start = start
#         self.end = end
#         self.current = start
#
#     def __iter__(self):
#         return self
#
#     def __next__(self):
#         if self.current < self.end:
#             value = self.current
#             self.current += 1
#             return value
#         else:
#             raise StopIteration
#
# # 使用自定义迭代器
# my_range = MyRange(0, 5)
# for num in my_range:
#     print(num)